#ifndef SOCKET_H
#define SOCKET_H

#include <QObject>
#include <QTcpSocket>
#include <QList>
#include <QTimer>

#include "../common/streamer.h"
#include "serverhandler.h"

/**
 * @brief The Socket class
 * @brief 管理连接
 */
class Socket : public QObject
{
    Q_OBJECT
private:
    friend class Server;
    explicit Socket(QTcpSocket* socket, QObject *parent = nullptr);

public:
//    ~Socket();
    inline qint64 write(const QByteArray& data){ return socket->write(data); }

    void setRoom(QString& ID){roomid = ID;}
    void setUserName(QString& name){username = name;}
    QString& getRoom(){return roomid;}
    QString& getUserName(){return username;}
    void clearRoom(){roomid.clear();}
    void heartcheck();

private slots:
    void onReadyRead();
    void onDisconnected();

signals:

private:
    QTcpSocket* socket;

    Streamer streamer;
    ServerHandler handler;

    QString username;
    QString roomid;
};

#endif // SOCKET_H
